<template>

  <div>
   
    <form class="form-signin">
      <div class="text-center mb-4">
        <img src="~/assets/login/image/login.png" alt="登录">
      </div>

      <div class="form-label-group">
        <input
          type="text"
          id="username"
          placeholder="用户名"
          v-model="user.username"
          class="form-control"
          required
          autofocus
        >
        <label for="username">用户名</label>
      </div>

      <div class="form-label-group">
        <input
          type="password"
          id="password"
          placeholder="密码"
          v-model="user.password"
          class="form-control"
          required
        >
        <label for="password">密码</label>
      </div>
      <div class="form-label-group">
        <input
          type="email"
          id="email"
          class="form-control"
          v-model="user.email"
          placeholder="邮箱"
          required
        >
        <label for="email">邮箱</label>
      </div>
      <div class="form-label-group">
        <input
          type="text"
          id="authCode"
          class="form-control"
          v-model="authCode"
          placeholder="验证码"
          required
        >
        <label for="authCode">验证码</label>
      </div>
      <div class="checkbox mb-3">
        <center>
          <el-button type="primary" @click="register()">注册</el-button>
          <br>
         <nuxt-link to="/login"><el-button type="text">已有帐号?快去登录吧</el-button></nuxt-link> 
        </center>
      </div>
    </form>
  </div>
</template>
<script>
import userApi from "@/api/user";
export default {
   layout: 'login',
  data() {
    return {
      user: {}, //用户信息
      authCode: "" //验证码
    };
  },
  methods: {
    register() {
  
      userApi.register(this.user,this.authCode).then(resp => {
        this.$message({  
          message: resp.data.msg,
          type: resp.data.flag ? 'success' : 'error'
        });
        if(resp.data.flag){
          location.href="/login";
        }
      });
    }
  }
};
</script>